from fdlite import FaceDetection, FaceLandmark, face_detection_to_roi
from fdlite import IrisLandmark, iris_roi_from_face_landmarks
from fdlite import iris_depth_in_mm_from_landmarks
from PIL import Image

# load detection models
detect_faces = FaceDetection()
detect_face_landmarks = FaceLandmark()
detect_iris = IrisLandmark()

# open image
img = Image.open('11111.jpg')
print(type(img))
print(img.size)
print(img.shape)
# detect face
face_detections = detect_faces(img)
if len(face_detections):
    # get ROI for the first face found
    face_roi = face_detection_to_roi(face_detections[0], img.size)
    # detect face landmarks
    face_landmarks = detect_face_landmarks(img, face_roi)
    # get ROI for both eyes
    eye_roi = iris_roi_from_face_landmarks(face_landmarks, img.size)
    left_eye_roi, right_eye_roi = eye_roi
    # detect iris landmarks for both eyes
    left_eye_results = detect_iris(img, left_eye_roi)
    right_eye_results = detect_iris(img, right_eye_roi, is_right_eye=True)
    # print(f'left_eye_results={left_eye_results}')
    # print(f'right_eye_results={right_eye_results}')
    # change the iris color
    dist_left_mm, dist_right_mm = iris_depth_in_mm_from_landmarks(
        img, left_eye_results, right_eye_results)
    #(26,3,4224,5632)
    print(f'Distance from camera appr. {dist_left_mm//10} cm to '
          f'{dist_right_mm//10} cm')
else:
    print('no face detected :( ')
